﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using qltscd.Models;
using qltscd.Contansts;

namespace qltscd.Helper {
    public static class KeyHelper {
        public static string GetMaDanhMucThietBi () {
            QLTBEntities db = new QLTBEntities();
            string maxMa = db.DanhMucThietBis.OrderByDescending(i => i.MaThietBi).FirstOrDefault().MaThietBi;
            string identity = maxMa.Replace(KeyContansts.DanhMucThietBiPrefix, "");
            int iden = Convert.ToInt32(identity);
            iden++;
            int numberOfZero = 6;
            while (iden / 10 > 0) {
                numberOfZero--;
            }
            string zeros = "";
            for (int i = 0; i < numberOfZero; i++) {
                zeros += "0";    
            }
            return KeyContansts.DanhMucThietBiPrefix + zeros + iden;
        }
    }
}